<?php
/**
 *    Copyright 2010 Show Framework(www.showframework.cn)
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 * 
 *        http://www.apache.org/licenses/LICENSE-2.0
 * 
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

/**
 * Show Framework 默认配置类
 * 
 * @package Show_Config
 * @name Show_Config_Default
 * @author show
 * @since v0.6
 */
class Show_Config_Default extends Show_Config
{
    /**
     * 构造函数
     * Show_Config_Default是框架默认配置加载类
     * 从符合show framework配置文件格式的文件中加载配置信息
     * 
     * $config = new Show_Config_Default('../../config.sample.php');
     * echo $config->version, "\n";
     * echo $config->url->_404, "\n";
     * echo $config->db->mysql->charset, "\n";
     *
     * @param string $file 配置源文件
     * @return void
     */
    public function __construct($file)
    {
        $defaultArray = $this->load($file);
        parent::__construct($defaultArray);
    }
    
    /**
     * 从配置文件加载配置信息成为数组
     *
     * @param string $file
     * @return array
     */
    protected function load($file)
    {
        if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'php') {
            include_once $file;
            return get_defined_vars();
        } else {
            trigger_error(__METHOD__ . " 文件($file)不是合法的Show Framework配置文件，需要.php文件", E_USER_ERROR);
        }
    }
}
?>